
package com.vc.videosdk.xlog
import android.os.Environment
import com.elvishew.xlog.LogConfiguration
import com.elvishew.xlog.LogLevel
import com.elvishew.xlog.XLog
import com.elvishew.xlog.flattener.ClassicFlattener
import com.elvishew.xlog.printer.AndroidPrinter
import com.elvishew.xlog.printer.file.FilePrinter
import com.elvishew.xlog.printer.file.backup.FileSizeBackupStrategy
import com.elvishew.xlog.printer.file.clean.FileLastModifiedCleanStrategy
import com.elvishew.xlog.printer.file.writer.SimpleWriter


/**

 * @Author : wy

 * @Time : On 2024/9/13 15:07

 * @Description : XLogUtil

 */
object XLogUtil {
    fun init() {
        val config = LogConfiguration.Builder()
            .logLevel(LogLevel.ALL)
            .tag("VCSdk")
            .enableThreadInfo()
            .build();

        val androidPrinter =
            AndroidPrinter(true)//// Printer that print the log using android.util.Log

        val logFolder =
            Environment.getExternalStorageDirectory().path + "/vc_sdk"

        val filePrinter = FilePrinter.Builder(logFolder)
            .fileNameGenerator(MyFileNameGenerator())//日志文件名格式
            .backupStrategy(FileSizeBackupStrategy((300 * 1024 * 1024).toLong()))//单个日志文件的大小默认:FileSizeBackupStrategy(1024 * 1024)
            .cleanStrategy(FileLastModifiedCleanStrategy(5L * 24L * 60L * 60L * 1000L))//日志文件存活时间，单位毫秒
            .flattener(ClassicFlattener())//配置写入文件日志格式
            .writer(SimpleWriter())//配置日志写入
            .build()

        XLog.init(config, androidPrinter, filePrinter)
    }

    fun d(msg: String) {
        XLog.d(msg)
    }

    fun i(msg: String) {
        XLog.i(msg)
    }

    fun e(msg: String) {
        XLog.e(msg)
    }

    fun w(msg: String) {
        XLog.w(msg)
    }

    fun v(msg: String) {
        XLog.v(msg)
    }
}